package GUI;

import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.util.Vector;

import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowSorter;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import CommonGui.NotEdditibleTable;
import DataObjects.ConstantObjects;
import Messages.MessageGetAllItemsForNewRecipe;
import Messages.MessageGetAllItemsForNewRecipeReply;
import Messages.MessageGetPriceItemByNameItem;

import Messages.MessageGetPriceItemByNameItemReply;
import Messages.MessageShowIDRecipe;
import Messages.MessageShowIDRecipeReply;

import javax.swing.ListModel;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PfAdd_new_recipeTRY extends JPanel{
	
	private int count_res_menuRecipes=0;
	private int mId;
	private float price;
	private float totalPrice;
	private String flag;
	private JComboBox statusRecipe;
	
	private JTextField itemTxt;
	private JTextField medidaTxt;
	private JTextField weightTxt;
	private JTextField	costTxt;
	private JTextField textField_RecipeId;
	private JTextField	textField_nameRecipe;
	private JTextField textField_price;
	private JTextField costItemTxt;
	private JTextField reallyCostItemTxt;
	private JTextField nameTF1;
	private JTextField nameTF2;
	
	private RowSorter<DefaultTableModel> sorterName;
	
	
	private String menuId;
	private MainMenu mainMenu;
	
	private JPanel totalPanel;
	private JPanel bulkiPanel;
	private JPanel leftPanel;
	private JPanel rightPanel;
	private JPanel detailsPanel;
	private JPanel tablePanel;
	private JPanel allItemsPanel;
	private JPanel greatMiddlePanel;
	private JPanel	greatButtonsCategoryPanel;
	private JPanel middlePanel;
	private JPanel suppItemsPanel;
	private JPanel  allItemsListPanel;
	private JPanel allItemsPanelSearch;
	private JPanel recipeItemsPanelSearch;
	private JPanel recipeItemsListPanel;
	private JPanel buttonsPanel;
	private JPanel costRecipePanel;
	
	private JList allItemsList;
	private JList menuItemsList;
	private DefaultListModel allItemsModel;
	private DefaultListModel recipeItemsModel;
	
	
	private Vector<Vector> res_allItems;                 
	private Vector<Vector> res_recipeItems; 

	
	private JButton leftButton;
	private JButton rightButton;
	
	private JTable tbl;
	private NotEdditibleTable dtm;
	private Component horizontalGlue;
	private Vector <String> tblheader;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel label_3;
	private JLabel label_4;
	private JLabel label_5;
	private JTextField mishkalTxt;
	private JTextField textField_6;
	private JLabel label_6;
	private JLabel label_7;
	private JTextField textField_7;
	private JButton button;
	private JLabel label_8;
	private JLabel label_9;
	private JLabel label_10;
	private JLabel label_11;
	private JLabel label_12;
	private JComboBox comboBox_1;
	private JTextField textField_8;
	private JTextField textField_9;
	private JTextField textField_10;
	private JTable table;
	
	
	public PfAdd_new_recipeTRY (MainMenu mm)
	{
		super();
		this.mainMenu=mm;
		this.setLayout(null);
		//this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		initialize();
	}
	
	private void initialize()
	{
		getLeftHipus();
		getListAllItems();
		getRightHipus();
		getListRecipeItemsPanel();
		getButtonsOfMiddleArea();
		getButtonsOfRecipeDetails();
		
	}
	
	private void getLeftHipus()
	{
		JLabel searchLbl=new JLabel("חיפוש לפי שם המוצר :");
		searchLbl.setBounds(161, 37, 113, 20);
		this.add(getNameTF1());
		getNameTF1().setBounds(64, 37, 83, 20);
		this.add(searchLbl);
		
	}
	
	
	private JTextField getNameTF1()
	{
		nameTF1=new JTextField(20);
		nameTF1.setHorizontalAlignment(JTextField.RIGHT);
	
		KeyListener keyListener = new KeyListener() 
		{		      
			public void keyPressed(KeyEvent arg0) {}

			public void keyReleased(KeyEvent arg0) 
			{
				JTextField nameField = (JTextField)arg0.getSource();
				String selectedName = (String)nameField.getText();
				filterByName1(selectedName);				
			}

			public void keyTyped(KeyEvent arg0) {}		
		};
		
		nameTF1.addKeyListener(keyListener);		
		return nameTF1;
	}
	
	//filter for all items list
	private void filterByName1(String str)
	{
		allItemsModel.clear();
		for(int i=0;i<res_allItems.size();i++)
		{
			if(((String)res_allItems.get(i).get(1)).startsWith(str))
			allItemsModel.addElement((String) res_allItems.get(i).get(1));  
		}
	}
	
	private void getListAllItems ()         
	{
				
		allItemsModel=new DefaultListModel();
		MessageGetAllItemsForNewRecipe allItems=new MessageGetAllItemsForNewRecipe();
		try {
			mainMenu.ms.client.sendToServer(allItems);
			MessageGetAllItemsForNewRecipeReply result = (MessageGetAllItemsForNewRecipeReply)mainMenu.ms.client.GetMessage();
		//	this.res_allItems=result.getRecipes();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
		int size_vector=res_allItems.size();		
		for(int i=0;i<size_vector;i++) 
		{
			allItemsModel.addElement((String) res_allItems.get(i).get(1));          //Enter all items's names to listmodel
		}
		
		allItemsList = new JList(allItemsModel);
		allItemsList.setBounds(20, 78, 244, 687);
		allItemsList.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		allItemsList.setFont(new Font("Tahoma", Font.PLAIN, 14));
		allItemsList.setBackground(new Color(230, 230, 250));
		this.add(allItemsList);
		
		JButton btnNewButton = new JButton("New button");
		btnNewButton.setBounds(10, 27, 44, 40);
		add(btnNewButton);
	
		//JScrollPane listScroller1 = new JScrollPane(allItemsList);
	//	listScroller1.setPreferredSize(new Dimension(200, 600));
	//	this.add(listScroller1);
		String selectedItem=(String)allItemsList.getSelectedValue();
		allItemsList.addListSelectionListener(new ListSelectionListener() 
	 	{
	 	      public void valueChanged(ListSelectionEvent evt) {
	 	        if (evt.getValueIsAdjusting())
	 	        return;
	 	      	     
	 	      JList itemList=(JList) evt.getSource();
	          String value=(String) itemList.getSelectedValue();
	          itemTxt.setText(value);
	          reallyCostItemTxt.setText("");
	          costItemTxt.setText("");
	          weightTxt.setText("");
	          medidaTxt.setText("");
	          for(int i=0;i<res_allItems.size();i++) 
	  		{
	  			if(value==res_allItems.get(i).get(1))
	  			{
	  				medidaTxt.setText((String)res_allItems.get(i).get(6));
	  				break;
	  			}
	  		}
	          ;
	 	       
	 	   
	 	      }
	 	    });
			
	}
	
	private void getRightHipus()
	{
		JLabel searchLbl1=new JLabel("חיפוש לפי שם המוצר :");
		searchLbl1.setBounds(570, 37, 113, 20);
		this.add(getNameTF2());
		getNameTF2().setBounds(454, 37, 88, 20);
		this.add(searchLbl1);
		
	}
	
	
	private JTextField getNameTF2()
	{
		nameTF2=new JTextField(20);
		nameTF2.setHorizontalAlignment(JTextField.RIGHT);
	
		KeyListener keyListener = new KeyListener() 
		{		      
			public void keyPressed(KeyEvent arg0) {}

			public void keyReleased(KeyEvent arg0) 
			{
				JTextField nameField = (JTextField)arg0.getSource();
				String selectedName = (String)nameField.getText();
				filterByName2(selectedName);				
			}

			public void keyTyped(KeyEvent arg0) {}		
		};
		
		nameTF2.addKeyListener(keyListener);		
		return nameTF2;
	}
	
	//filter for all items list
	private void filterByName2(String str)
	{
		recipeItemsModel.clear();
		for(int i=0;i<res_recipeItems.size();i++)
		{
			if(((String)res_recipeItems.get(i).get(0)).startsWith(str))
				recipeItemsModel.addElement((String) res_recipeItems.get(i).get(0));  
		}
	}
	
	private void getListRecipeItemsPanel ()          
	{
				
		recipeItemsModel=new DefaultListModel();
		menuItemsList = new JList(recipeItemsModel);
		menuItemsList.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		menuItemsList.setFont(new Font("Tahoma", Font.PLAIN, 14));
		menuItemsList.setBackground(new Color(230, 230, 250));
		menuItemsList.setBounds(454, 78, 244, 687);
		this.add(menuItemsList);
		
		
		//JScrollPane listScroller2 = new JScrollPane(menuItemsList);
		//listScroller2.setPreferredSize(new Dimension(200, 600));
		//recipeItemsListPanel.add(listScroller2);
		
		menuItemsList.addListSelectionListener(new ListSelectionListener() 
	 	{
	 	      public void valueChanged(ListSelectionEvent evt) {
	 	        if (evt.getValueIsAdjusting())
	 	        return;
	 	      	     
	 	      JList itemList=(JList) evt.getSource();
	          String value=(String) itemList.getSelectedValue();
	          itemTxt.setText(value);
	          while(count_res_menuRecipes<res_recipeItems.size()){
	        	  
           	   if(value==(String)res_recipeItems.get(count_res_menuRecipes).get(0)){
           		   
           		medidaTxt.setText((String) res_recipeItems.get(count_res_menuRecipes).get(5));  
           		reallyCostItemTxt.setText((String) res_recipeItems.get(count_res_menuRecipes).get(1));
           		costItemTxt.setText((String) res_recipeItems.get(count_res_menuRecipes).get(4));
           		weightTxt.setText((String) res_recipeItems.get(count_res_menuRecipes).get(2));
           		
           		
           		medidaTxt.setEditable(false);
           		itemTxt.setEditable(false);
           	   }
	          count_res_menuRecipes++;
	          }
	          count_res_menuRecipes=0;
	 	      mainMenu.validate();
	 	      }
	 	    });
		
	
	}
	
	
	private void getButtonsOfMiddleArea()
	{
		JComboBox	categoryItem =new JComboBox(new ConstantObjects().getItemCategories());
		categoryItem.addActionListener(new java.awt.event.ActionListener() 
			  	{
					public void actionPerformed(java.awt.event.ActionEvent e) {
						JComboBox roleBox = (JComboBox)e.getSource();
					    String selectedRole = (String)roleBox.getSelectedItem(); 
					    
					
						} 
				});	
		categoryItem.setBounds(316, 96, 86, 20);
		add(categoryItem);
				
		this.add(getRightButton());
		this.add(getLeftButton());
		
		
		
		JLabel label = new JLabel("קטגוריה:");
		label.setBounds(337, 71, 46, 14);
		add(label);
		
		itemTxt = new JTextField();
		itemTxt.setHorizontalAlignment(JTextField.RIGHT);
		itemTxt.setBounds(316, 289, 86, 20);
		add(itemTxt);
		itemTxt.setColumns(10);
		
		medidaTxt = new JTextField();
		medidaTxt.setColumns(10);
		medidaTxt.setHorizontalAlignment(JTextField.RIGHT);
		medidaTxt.setBounds(316, 343, 86, 20);
		add(medidaTxt);
		
		weightTxt = new JTextField();
		weightTxt.setColumns(10);
		weightTxt.setHorizontalAlignment(JTextField.RIGHT);
		weightTxt.setBounds(316, 392, 86, 20);
		add(weightTxt);
		
		costItemTxt = new JTextField();
		costItemTxt.setColumns(10);
		costItemTxt.setHorizontalAlignment(JTextField.RIGHT);
		costItemTxt.setBounds(316, 447, 86, 20);
		add(costItemTxt);
		
		reallyCostItemTxt = new JTextField();
		reallyCostItemTxt.setColumns(10);
		reallyCostItemTxt.setHorizontalAlignment(JTextField.RIGHT);
		reallyCostItemTxt.setBounds(316, 502, 86, 20);
		add(reallyCostItemTxt);
		
		label_1 = new JLabel("שם המוצר:");
		label_1.setBounds(337, 259, 86, 14);
		add(label_1);
		
		label_2 = new JLabel("יח' מדידה:");
		label_2.setBounds(337, 320, 65, 14);
		add(label_2);
		
		label_3 = new JLabel("כמות:");
		label_3.setBounds(361, 374, 46, 14);
		add(label_3);
		
		label_4 = new JLabel("עלות לפי חישוב המערכת:");
		label_4.setBounds(303, 423, 141, 14);
		add(label_4);
		
		label_5 = new JLabel("עלות אמיתית:");
		label_5.setBounds(326, 477, 99, 14);
		add(label_5);
		
		mishkalTxt = new JTextField();
		mishkalTxt.setBounds(454, 814, 88, 20);
		add(mishkalTxt);
		mishkalTxt.setColumns(10);
		
		costTxt = new JTextField();
		costTxt.setColumns(10);
		costTxt.setBounds(613, 814, 85, 20);
		costTxt.setHorizontalAlignment(JTextField.RIGHT);
		costTxt.setEditable(false);
		add(costTxt);
		
		label_6 = new JLabel("סה\"כ המשקל:");
		label_6.setBounds(626, 786, 84, 14);
		add(label_6);
		
		label_7 = new JLabel("סה\"כ העלות:");
		label_7.setBounds(464, 786, 84, 14);
		add(label_7);
		
		
		
		button = new JButton("שינוי");
		button.setBounds(828, 183, 59, 35);
		add(button);
			
	}
	
	//=========================================================	KeyListener for the JTextField weightTxt (quantity of anything item)========================================
		/**
		 * KeyListener for the JTextField weightTxt (quantity of anything item) for calculate cost of selected item by quantity
		 */
		KeyListener keyListener1 = new KeyListener() 
		{		      
			public void keyPressed(KeyEvent arg0) {}
			public void keyReleased(KeyEvent arg0) 
			{
				MessageGetPriceItemByNameItem msgShowPrice=new MessageGetPriceItemByNameItem(itemTxt.getText() );
				
				try {
					mainMenu.ms.client.sendToServer(msgShowPrice);
					MessageGetPriceItemByNameItemReply resultID=(MessageGetPriceItemByNameItemReply)mainMenu.ms.client.GetMessage();
					price=Float.parseFloat(resultID.getItemPrice());	
				    price=price*(Float.parseFloat(weightTxt.getText()));
				    costItemTxt.setText(Float.toString(price));
				    reallyCostItemTxt.setText(Float.toString(price));
				} catch (IOException e) {
					
					e.printStackTrace();
				}
			}
			public void keyTyped(KeyEvent arg0) {}		
		};
		
	//====================================================================================================================================================================
	
	
	
	
	
	private void getButtonsOfRecipeDetails()
	{
		
		
		
		
		label_10 = new JLabel("משקל מתכון:");
		label_10.setBounds(1004, 193, 81, 14);
		add(label_10);
		
		
		
		label_12 = new JLabel("סטטוס מתכון:");
		label_12.setBounds(1004, 320, 81, 14);
		add(label_12);
		
		comboBox_1 = new JComboBox();
		comboBox_1.setBounds(897, 317, 97, 35);
		add(comboBox_1);
		
		
		
		
		textField_RecipeId = new JTextField();
		textField_RecipeId.setBounds(897, 37, 97, 37);
		textField_RecipeId.setHorizontalAlignment(JTextField.RIGHT);
		textField_RecipeId.setColumns(10);
		MessageShowIDRecipe msgShowID=new MessageShowIDRecipe( );
		try {
			mainMenu.ms.client.sendToServer(msgShowID);
			MessageShowIDRecipeReply resultID=(MessageShowIDRecipeReply)mainMenu.ms.client.GetMessage();
		    mId=Integer.parseInt(resultID.getResultID());	
			
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
		 mId=mId+1;
		 textField_RecipeId.setText(Integer.toString(mId));
		 textField_RecipeId.setColumns(10);
		 textField_RecipeId.setEditable(false);
		 textField_RecipeId.setBackground(Color.pink);
		 
			JLabel rid = new JLabel("מספר המתכון:", JLabel.TRAILING);
			rid.setForeground(new Color(75, 0, 130));
			rid.setFont(new Font("Tahoma", Font.BOLD, 12));
			rid.setLabelFor(textField_RecipeId);
			rid.setBounds(1004, 39, 81, 14);
			add(textField_RecipeId);
			add(rid);
			
			
			textField_nameRecipe = new JTextField();
			textField_nameRecipe.setHorizontalAlignment(JTextField.RIGHT);
			textField_nameRecipe.setColumns(10);
			textField_nameRecipe.setBounds(897, 112, 97, 37);
		    add(textField_nameRecipe);
		
		    JLabel name = new JLabel("שם המתכון:", JLabel.TRAILING);
			name.setForeground(new Color(75, 0, 130));
			name.setFont(new Font("Tahoma", Font.BOLD, 12));
			name.setLabelFor(textField_nameRecipe);	
			name.setBounds(1004, 122, 81, 14);
			
			
			//======================================================CHECK FOR CORRECT INPUT NAME==================================================
			/**
			 * CHECK FOR CORRECT INPUT NAME
			 */
			KeyListener keyListener1 = new KeyListener() 
			{		      
				public void keyPressed(KeyEvent arg0) {}

				public void keyReleased(KeyEvent arg0) 
				{
					JTextField nameField1 = (JTextField)arg0.getSource();
					String selectedName1 = (String)nameField1.getText();
					if(selectedName1.length()==0)
					{
						textField_nameRecipe.setBackground(Color.white);
					}
					for(int i=0;i<selectedName1.length();i++)
					{
					
						textField_nameRecipe.setBackground(Color.pink);
					
					}
				}

				public void keyTyped(KeyEvent arg0) {}		
			};	
			textField_nameRecipe.addKeyListener(keyListener1);		
			
			//======================================================================================================================
			add(name);
			add(textField_nameRecipe);
			
			
			textField_price = new JTextField();
			textField_price.setHorizontalAlignment(JTextField.RIGHT);
			textField_price.setFont(new Font("Tahoma", Font.PLAIN, 13));
			textField_price.setBounds(897, 247, 97, 37);
			textField_price.setColumns(10);
			add(textField_price);
			
			JLabel labelPrice = new JLabel("עלות המתכון:", JLabel.TRAILING);
			labelPrice.setForeground(new Color(75, 0, 130));
			labelPrice.setBounds(1004, 258, 81, 14);
			labelPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
			labelPrice.setLabelFor(textField_price);
			
			
			//===========================================CHECK FOR CORRECT INPUT PRICE==================================================
			/**
			 * CHECK FOR CORRECT INPUT PRICE
			 */
			
			KeyListener keyListener = new KeyListener() 
			{		      
				public void keyPressed(KeyEvent arg0) {}

				public void keyReleased(KeyEvent arg0) 
				{
					JTextField nameField = (JTextField)arg0.getSource();
					String selectedName = (String)nameField.getText();
					if(selectedName.length()==0)
					{
						textField_price.setBackground(Color.white);
					}
					for(int i=0;i<selectedName.length();i++)
					{
					if (selectedName.charAt(i) <'0'|| selectedName.charAt(i)>'9')
		    		 {
		    			 
						textField_price.setBackground(Color.RED);
						 break;
		    		 }
					else
					{
						textField_price.setBackground(Color.pink);
					}
					}
				}

				public void keyTyped(KeyEvent arg0) {}		
			};
			
			textField_price.addKeyListener(keyListener);	
		//=============================================================================================================================
			add(textField_price);
			add(labelPrice);
			
					
		
		
		textField_10 = new JTextField();
		textField_10.setColumns(10);
		textField_10.setBounds(897, 182, 97, 37);
		add(textField_10);
		
		//table = new JTable();
	//	table.setBounds(778, 374, 428, 460);
		add(table);
	}

	
	
	
	

private JButton getRightButton()
{
	rightButton=new JButton("--->");
	rightButton.setBounds(316, 155, 89, 23);
	res_recipeItems = new Vector<Vector>();
	rightButton.addActionListener(new java.awt.event.ActionListener() {
		public void actionPerformed(java.awt.event.ActionEvent e) {
			
		String selectedItem=(String)allItemsList.getSelectedValue();
			if (selectedItem!=null)
			{
				if(weightTxt.getText().isEmpty()){
		    		 JOptionPane.showMessageDialog(null,"יש לקבוע כמות המוצר");
		    		 return;	
		    				 }
				else{
				
				totalPrice=totalPrice+Float.parseFloat(reallyCostItemTxt.getText());
				String weight=weightTxt.getText();
				String reallyCostItem=reallyCostItemTxt.getText();
				String costItem=costItemTxt.getText();
				String medida=medidaTxt.getText();
				costTxt.setText(Float.toString(totalPrice));
				allItemsModel.removeElement(selectedItem);
				recipeItemsModel.addElement(selectedItem);
				for(int i=0; i<res_allItems.size();i++)
				{
				     if(res_allItems.get(i).get(1).equals(selectedItem))
				     {
				    	 Vector<String> row=new Vector<String>();
				    	 row.add((String) res_allItems.get(i).get(1));                 //Item name
				    	 row.add(reallyCostItem) ;	                                   //Cost of item this 
				    	 row.add((String) res_allItems.get(i).get(6));                 //ehidot medida
				    	 row.add(weight) ;					    	                   //Quantity of item this
				    	
				    	 row.add((String) res_allItems.get(i).get(0));                 //Item ID
				    	 row.add(costItem) ;	                                       //Cost of item that program calculate 
				    	 row.add( medida) ;	                                           //Medida of item
				    	 
				    	// res_recipeItems.add(row);                                     // res_recipeItems - vector that have ID,Name and quantity and really cost
				    	
				    	// tbl.repaint();
				    	 NotEdditibleTable orderModel = (NotEdditibleTable) (tbl
									.getModel());
							orderModel.addRow(row);
							tbl.setModel(orderModel);
				    	// dtm.setDataVector(res_recipeItems, tblheader); 
				    	 medidaTxt.setText("");
				    	 weightTxt.setText("");
				    	// reallyCostItemTxt.setText("");
				    	 costItemTxt.setText("");
				    	break;
				     					    	
				     }
				 }
				     
				}
		}			
			else
			{
				JOptionPane.showMessageDialog(null,"יש לבחור פריט");
			}
					
		}
	});
		
	return rightButton;		
}

private JButton getLeftButton()
{
	leftButton=new JButton("<---");
	leftButton.setBounds(316, 207, 89, 23);
	leftButton.addActionListener(new java.awt.event.ActionListener() {
		public void actionPerformed(java.awt.event.ActionEvent e) {
			
			String selectedItem=(String)menuItemsList.getSelectedValue();
			if (selectedItem!=null)
			{
				recipeItemsModel.removeElement(selectedItem);
				allItemsModel.addElement(selectedItem);
				for(int i=0; i<res_recipeItems.size();i++)
				{
				     if(res_recipeItems.get(i).get(0).equals(selectedItem))
				     {
				    	 totalPrice=totalPrice-(Float.parseFloat(reallyCostItemTxt.getText()));
				    	 costTxt.setText(String.valueOf(totalPrice));
				    	 res_recipeItems.remove(i);
				    	 itemTxt.setText("");
				    	 medidaTxt.setText("");
				    	 costItemTxt.setText("");
				    	 reallyCostItemTxt.setText("");
				    	 weightTxt.setText("");
				    	 tbl.repaint();
				    	break;
				     }
				}
			} 
			
			else
			{
				JOptionPane.showMessageDialog(null,"יש לבחור פריט");
			}
					
		}
	});
	
	return leftButton;		
}





/**
 * Method for check correctness of input
 * @return Integer result
 */
private int inputCheck()
 {
	int result=0;
	
	
	//=================================================check for empty price and name================================		
	
	
	String price=textField_price.getText();
	String name=textField_nameRecipe.getText();
	String selectedRole = (String)statusRecipe.getSelectedItem(); ; 
	if(price.isEmpty() && name.isEmpty())
	{
		JOptionPane.showMessageDialog(null,"יש להקיש שם ולקבוע עלות למתכון");	
		textField_nameRecipe.setBackground(Color.RED);
		textField_price.setBackground(Color.RED);
		result=1;
	}
	else
		if(price.isEmpty())
		{
			JOptionPane.showMessageDialog(null,"יש לקבוע עלות");	
			textField_price.setBackground(Color.RED);
			result=1;
		}
		else
		if(name.isEmpty())
		{
			JOptionPane.showMessageDialog(null,"יש לתת שם למתכון");	
			textField_nameRecipe.setBackground(Color.RED);
			result=1;
		}
	
	//=================================================check for price================================		
	/**
	 * check correctness of price
	 */		
	if(result==0)
	{
	for(int i=0;i<price.length();i++)
	{
	if (price.charAt(i) <'0'|| price.charAt(i)>'9')
	 {
		JOptionPane.showMessageDialog(null,"עלות שגויה.יש להקיש ספרות לבד.");	
		textField_price.setBackground(Color.RED);
		result=1;
		 break;
	 }
	else
	{
		textField_price.setBackground(Color.pink);
	}
	
	}
	
	
 }
	
	//=================================================check for status================================		
	/**
	 * Check correctness of status
	 */
	if(result==0)
	{
	if(selectedRole.equals("פעיל") || selectedRole.equals("לא פעיל"))
    {
    	
		statusRecipe.setBackground(Color.pink);
    		    	
	}
    else
    {
    	JOptionPane.showMessageDialog(null,"יש לבחור סטטוס");	
    	statusRecipe.setBackground(Color.RED);
    	result=1;
    }
	
	}
	return result;
}
}